﻿<ul class="unit-list forum-post">
@if((Model.Posts.Items as IEnumerable<dynamic>).Any())
{
    foreach(var i in Model.Posts.Items)
    {
        bool markedAsUseful = JDM.HasFlags(i.Flags, "Useful");
        bool markedAsUseless = JDM.HasFlags(i.Flags, "Useless");
        <li class="unit forum-topic-entry forum-post @(markedAsUseful ? "useful" : String.Empty) @(markedAsUseless ? "useless" : String.Empty)">
            <header>
                <nav>
                    @{
                        Html.RenderPartial("_Avatar", (object)i.Member);
                    }
                    <span class="separator">&nbsp;</span>
                    <span>@Svc.DateTimeRel((DateTime)JDM.DateTime(i.CreatedOn))</span>
                    <a href="@Url.Action(Loc.Act("Show").Ctrl("Account").NoArea().Set(new
                    {
                        id = JDM.Int32(i.Member.Account.EntityID)
                    }).Localized())">@T(Res.In("Common").Of("Expr").Name("By"), JDM.String(i.Member.Account.Username))</a>
                    @if(Svc.IsAuthenticated)
                    {
                        bool postAuthor = JDM.Int32(i.Member.EntityID) == JDM.Int32(Svc.ForumMember.EntityID);
                        bool topicAuthor = JDM.Int32(Model.Topic.Member.EntityID) == JDM.Int32(Svc.ForumMember.EntityID);
                        if(Model.UserCanWrite)
                        {
                            <span class="separator">&middot;</span>
                            <a href="@Url.Action(Loc.Act("Create").Ctrl("ForumPost").Area("Wizard").Set(new
                            {
                                topicID = JDM.Int32(i.Topic.EntityID),
                                parentID = JDM.Int32(i.EntityID)
                            }).Localized())">@T(Res.Name("Reply"))</a>
                        }
                        if(Model.UserCanModerate || postAuthor)
                        {
                            <span class="separator">&middot;</span>
                            <a href="@Url.Action(Loc.Act("Edit").Ctrl("ForumPost").Area("Wizard").Set(new
                            {
                                id = JDM.Int32(i.EntityID)
                            }).Localized())">@T(Res.In("Common").Of("Act").Name("Edit"))</a>
                        }
                        if(Model.UserCanModerate || (topicAuthor && !postAuthor && !markedAsUseful && !markedAsUseless))
                        {
                            <span class="separator">&middot;</span>
                            <span>@T(Res.Name("MarkAs"))</span>
                            <a href="@Url.Action(Loc.Act("MarkUseful").Ctrl("ForumPost").Area("Wizard").Set(new
                            {
                                id = JDM.Int32(i.EntityID)
                            }).Localized())">@T(Res.In("API").Of("Enum").Of("ForumPostFlags").Name("Useful"))</a>
                            <span class="separator">/</span>
                            <a href="@Url.Action(Loc.Act("MarkUseless").Ctrl("ForumPost").Area("Wizard").Set(new
                            {
                                id = JDM.Int32(i.EntityID)
                            }).Localized())">@T(Res.In("API").Of("Enum").Of("ForumPostFlags").Name("Useless"))</a>
                        }
                    }
                </nav>
            </header>
            <section class="@(markedAsUseful ? "useful" : String.Empty) @(markedAsUseless ? "useless" : String.Empty)">
                <div class="html text-long">
                    <p>@Html.Raw(BBCodeHelper.ToHtml(JDM.String(i.Text)))</p>
                </div>
                @{
                    Html.RenderPartial("_Signature", (object)i.Member);
                }
            </section>
        </li>
    }
}
else
{
    <li class="empty"><span>@T(Res.In("Common").Of("Expr").Name("NoData"))</span></li>
}
</ul>

